<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <h1>点我</h1>
    <h1>点我</h1>
    <h1>点我</h1>
    <h1>点我</h1>
</body>
<script src="./js/jq.js"></script>
<script src="./js/sizzle.js"></script>
<script>
    function jQuery(selector) {
        return new jQuery.fn.init(selector)
    }
    jQuery.fn = jQuery.prototype
    jQuery.prototype.init = function (selector) {
        if(typeof selector=='object'){
            [].push.call(this,selector)
        }else if(typeof selector=='string'){
            Sizzle(selector, document, this);
        }
        return this;
    }
    jQuery.prototype.init.prototype=jQuery.fn;
    jQuery.fn.css = function (key, val) {
        let arr = Array.from(this);
        arr.forEach((v) => {
            v.style[key]=val
        })
    }
    jQuery.fn.on = function (type, cb) {
        // console.log(this)
        let arr = Array.from(this);
        arr.forEach((val) => {
            val.addEventListener(type,function(){
                cb.call(this);
            })
        })
    }

    var $ = jQuery;
    $('h1').on('click', function () {
        $(this).css('color','red')
    })


</script>



</html>